 ///
 /// @file    Complex.cc
 /// @author  lemon(haohb13@gmail.com)
 /// @date    2016-03-04 11:30:48
 ///
 
#include <iostream>
using std::cout;
using std::endl;
using std::cin;


class Complex
{
	//friend std::ostream & operator<<(std::ostream &, const Complex & rhs);  
	friend std::istream & operator>>(std::istream &, Complex & rhs);
public:
	Complex(double dreal, double dimag)
	: _dreal(dreal)
	, _dimag(dimag)
	{
		cout << "Complex(doule, double)" << endl;
	}

	void print(std::ostream & os) const
	{
		os << _dreal;
		if(_dimag > 0)
			os << " + " << _dimag << "i";
		else if(_dimag < 0)
			os << " - " << (-1) * _dimag << "i";
	}

private://通过规则表达语义：该对象不能进行复制
	//Complex(const Complex &);
	//Complex & operator=(const Complex &);


private:
	double _dreal;
	double _dimag;
};

//输入输出运算符的重载必须是friend函数的形式进行重载
//不能是成员函数，因为它们要求第一个参数是流类型
//
//流对象不能进行复制
std::ostream & operator<<(std::ostream & os, const Complex & rhs) 
{
	rhs.print(os);
	return os;
}

std::istream & operator>>(std::istream & is, Complex & rhs)
{
	is >> rhs._dreal;
	while(is.get() != '*')
	{}
	is >> rhs._dimag;
	return is;
}

int main(void)
{
	Complex c1(3, 0);
	Complex c2(4, 5);
	cout << c1 << endl;
	c2 = c1;
	cout << c2 << endl;
	Complex c3(c2);

	cin >> c3;
	cout << c3 << endl;
	
}

